package com.example.config;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 麦健豪
 * @date 2020/10/13 12:08
 */
public class DateListConverter implements Converter<String[], Date[]> {
    private String datePattern = "yyyy-MM-dd";

    @Override
    public Date[] convert(String[] strings) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(datePattern);
        try {
            Date[] dates = new Date[2];
            for (int i = 0; i < strings.length; i++) {
                dates[i] = simpleDateFormat.parse(strings[i]);
            }
            return dates;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
